<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}


// link group listings
$getListGroupNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY linkGroup ASC");
$listGroupNames = mysql_fetch_assoc($getListGroupNames);


$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/navcategories.tpl");


// get link groups
do {
	$groupresult = $listGroupNames['linkGroup'];
		if ($storedGroupCategory != $groupresult && $groupresult != NULL) {
			if ($listGroupNames['linkGroup'] == 'None') {
			$box_content->assign("LINKGROUP",'<div class="linkGroup">Links</div>');
			} else {
			$box_content->assign("LINKGROUP",'<div class="linkGroup">'.$listGroupNames['linkGroup'].'</div>');
			}
		
		// category listing
		$getNavCategory = mysql_query("SELECT * FROM affiliSt_categories WHERE parent = '0' ORDER BY name ASC");
		$navCategoryList = mysql_fetch_assoc($getNavCategory);
		$storedCategory = '';

		// create navigation from category and brond list
			do { 
			$catresult = $navCategoryList['id'];
			if ($storedCategory != $catresult && $navCategoryList['linkGroup'] == $listGroupNames['linkGroup']) {
				if ($catresult == $_GET['nc']) {
						$box_content->assign("FONTSTYLE",'catNavOn');
				} else {
						$box_content->assign("FONTSTYLE",'catNavOff');
				}
					
					if ($navOpt[7] == 1) {
					// html perma
					$box_content->assign("LINKDATA",$installDir['value'].'categories/'.$catresult.'/'.urltxt($navCategoryList['name']).'.html');
					} else {
					// php link
					$box_content->assign("LINKDATA",$installDir['value'].'index.php?case=categories&nc='.$catresult);
					}
					
					$box_content->assign("DATA",$navCategoryList['name']);
					
					
					
					// brand listing
					$sql = sprintf("SELECT * FROM affiliSt_categories WHERE parent = %s ORDER BY RAND()",
									quote_smart($catresult));
					$getNavBrands = mysql_query($sql, $databaseConnect) or die(mysql_error());
					$navBrandList = mysql_fetch_assoc($getNavBrands);
					
					if ($navCategoryList['subLinks'] == 1 && $navBrandList['id'] != NULL) {
					
					
							$box_content->assign("OPENUL","<span>");
							$box_content->parse("navcategories.group.li.openul");
							$brandvalues = array();
							$brandlinkvalues = array();
							$brandrow = 0;
							
					do {
						$theresult = $navBrandList['id'];
						if ($storedBrand != $theresult) {
						
							if ($navOpt[7] == 1) {
							// html perma
							$brandlinkvalues[$brandrow] = $installDir['value'].'subcategories/'.$catresult.'/'.$theresult.'/'.urltxt($navCategoryList['name']).'/'.urltxt($navBrandList['name']).'.html';
							} else {
							// php link
							$brandlinkvalues[$brandrow] = $installDir['value'].'index.php?case=subcategories&nc='.$catresult.'&nb='.$theresult;
							}
							
							$brandvalues[$brandrow] = $navBrandList['name'];
							
						$storedBrand = $theresult;
						$brandrow++;
						} else {
						$theresult = $navBrandList['id'];
						}
					
			
					} while ($navBrandList = mysql_fetch_assoc($getNavBrands));
					
					
					$brandcount = count($brandvalues);
					if ($brandcount < 4) {
					$totalsublinks = $brandcount;
					} else {
					$totalsublinks = 4;
					}
					
					
					$nums = randiff(0,$brandcount,4);
					$var1 = $nums[0];
					$var2 = $nums[1];
					$var3 = $nums[2];
					$var4 = $nums[4];
					
					if($brandcount > 1) {
						for ($i=0; $i<$totalsublinks; $i++) {
								$box_content->assign("SUBFONTSTYLE",'brandNavOff');
								$box_content->assign("SUBLINKDATA",$brandlinkvalues[$var.$i]);
								$box_content->assign("SUBDATA",$brandvalues[$var.$i]);
								if ($i != $totalsublinks-1) {
								$box_content->assign("COMMA",',&nbsp;');
								} else {
								$box_content->assign("COMMA",'...<br />');
								}
								$box_content->parse("navcategories.group.li.subli");
						}
					}
					
							$box_content->assign("CLOSEUL","</span>");
							$box_content->parse("navcategories.group.li.closeul");
							
						
					
					}
					// end sub nav
					
				
			$box_content->parse("navcategories.group.li");
					
			
			$storedCategory = $catresult;
			} else {
			$catresult = ucwords(strtolower($navCategoryList['id']));
			}
			
			} while ($navCategoryList = mysql_fetch_assoc($getNavCategory)); 

		
		$box_content->parse("navcategories.group");
		$storedGroupCategory = $groupresult;
		} else {
		$groupresult = $listGroupNames['linkGroup'];
		}
} while ($listGroupNames = mysql_fetch_assoc($getListGroupNames));



			
$box_content->assign("TITLE","Browse Categories");
$box_content->assign("SKIN",$configSkin['value']);
$box_content->parse("navcategories");
$box_content = $box_content->text("navcategories");
?>